<template>
  <div style="flex:1; " class="flex">
      <criteria-paged :model="model" v-ref:paged  @sort="sort">
        <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
       <div novalidate class="form-inline" partial>

         <div class="form-group">
           <!-- <label>用户编号:</label> -->
           <input  type="text" class="form-control fixed-width" v-model="model.f_user_name" placeholder='用户姓名'
           condition="u.f_user_name = '{}'" v-next-el='bbh' v-filter v-focus>
         </div>
         <div class="form-group">
           <!-- <label>用户编号:</label> -->
           <input  type="text" class="form-control fixed-width" v-model="model.f_merternumber" placeholder='表号'
           condition="u.f_meternumber = '{}'" v-next-el='xq' v-filter v-focus v-el:bbh>
         </div>

         <div class="form-group">
           <input type="text" class="form-control" v-model="model.f_instruct_type" placeholder='指令类型'
           condition="i.f_instruct_type = '{}'"  id="f_instruct_type" v-el:xq v-next-el='cx'>
         </div>

         <div class="form-group">
           <input type="text" class="form-control" v-model="model.f_districtname" placeholder='小区'
           condition="u.f_residential_area like '%{}%'" id="f_residential_area" v-el:xq v-next-el='cx'>
         </div>
         <div class="form-group">
           <button class="btn btn-success active" @click="search()" v-el:cba>查询</button>
         </div>
       </div>
      </criteria>
      <data-grid  :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
             <th>序号</th>
             <th>用户编号</th>
             <th>用户信息</th>
             <th>表号</th>
             <th>指令类型</th>
              <th>指令内容</th>
             <th>指令状态</th>
             <th>上表状态</th>
             <th>指令生成时间</th>
             <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">{{$index+1}}</td>
            <td >{{row.f_userinfo_id}}</td>
            <td >{{row.f_user_name}}&nbsp;&nbsp;{{row.f_address}}</td>
            <td >{{row.f_meternumber}}</td>
            <td >{{row.f_instruct_type}}</td>
            <td >{{row.f_cmdparam}}</td>
            <td >{{row.f_instruct_state}}</td>
            <td >{{row.f_receive_state}}</td>
            <td >{{row.f_instruct_date}}</td>
            <td >
              <dropdown>
               <!-- <button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">
                 选择操作
               </button> -->
               <button type="button" data-toggle="dropdown" style="border: 0px;background: none;">
                 <span class="glyphicon glyphicon-th-list" style="position: inherit;"></span>
               </button>
               <ul slot="dropdown-menu" class="dropdown-menu dropdown-menu-right">
                 <li v-if="row.f_receive_state === '未知'">
                   <a href="#" @click.stop="$parent.$parent.$parent.operate(row.cmdid)"></span>查询</a>
                 </li>
               </ul>
             </dropdown>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
/**
*阶梯气价查询列表
*/
import { PagedList } from 'vue-client'
import * as Util from '../Util'
// import co from 'co'
// import Vue from 'vue'

// let findGen = function * (self, id) {
//   self.$resetpost('/WebMeterImplementation/rs/sql/singleTable', {tablename: 'cmdinfo', condition: `cmdid = ${id}`}).then(
//   (res) => {
//     console.log('res', res)
//   })
// }
export default {
  title: '指令查看',
  data () {
    return {
      model: new PagedList('rs/sql/queryInstruct', 20,
       {orderitem: '"' + this.orderitem + '"'})
    }
  },
  props: {
    orderitem: {
      type: Number,
      default: 'i.f_instruct_date DESC'
    },
    row: {}
  },
  ready () {
    this.search()
    console.log('this.row', this.model.rows[0])
  },
  methods: {
    operate (id) {
      console.log('id =', id)
      this.$resetpost('/rs/logic/getreceivestates', {data: {cmdid: id}}).then((res) => {
        console.log('res', res)
        this.search()
      })
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch (args) {
      if (!Util.f.parent.parent.name.includes('统一资源管理')) {
        args.condition = `${args.condition} and u.f_filiale = '${Util.f.f_fengongsi}'`
      }
      this.model.search(args.condition, args.model)
    }
  }
}
</script>
